#!/bin/bash
#leao:Wed Aug 21 05:18:41 PM CST 2024
#!/bin/bash  
function isLeapYear() {  
    if [ $[ $1 % 4 ] -eq 0 ] && [ $[ $1 % 100 ] -ne 0 ] || [ $[ $1 % 400 ] -eq 0 ]; then  
        return 1  
    else  
        return 0  
    fi  
}  
read -p "按格式输入时间 year month day: 
" year month day  
arr_day=(31 28 31 30 31 30 31 31 30 31 30 31)  
   
if isLeapYear $year; then  
    arr_day[1]=29  
fi  
total_days=0  
for (( i=0; i<$((month-1)); i++ ))
do  
    total_days=$((total_days + arr_day[i]))  
done   

if [ $day -le ${arr_day[month-1]} ]
then  
    total_days=$((total_days + day))  
else  
    echo "错误：输入的日期超出了当月的天数！"  
    exit 1  
fi  
    echo "年初距今已经过去 $total_days 天"  
